import pagination from '@/views/pagination'  //分页组件 
import dialogForm from './edit'
import agentHttp from '@/utils/agentHttp.js'
import {debounce,setEndDateTime} from '@/utils/index.js'
export default {
  name: 'frameChange',
  components:{dialogForm,pagination},
  created(){
    this.seachData();
    this.allButton = buttonPermission('all');
    this.updateButton= buttonPermission('update');
    this.viewButton= buttonPermission('view');
  },
  data() {
  	return {
      //搜索字段
  		searchForm:{
        startDate:"",
        endDate:"",
        carOrderStatus:"",
        logisticsFollowStatus:"",
  		},
      //表格字段
      tableData: {          
        },
        //发送给弹窗的数据
        dialogSendData:{
          isAdd:true,                //是否为编辑或者新增  true是   false否
          dialogFormVisible:false,   //弹窗是否显示        true是   false否
          id:""          //请求参数            自定义 例如index或者id
        },
        formLabelWidth:'120px',
        //弹窗或者查看页面信息
        dialogForm:{          
        },
        startDateOpt: {
          disabledDate(time) {
            return time.getTime() > Date.now() 
          }
        },
        endDateOpt:{
          disabledDate:(time)=>{
            return  time.getTime()< new Date(this.searchForm.startDate).getTime();
          }
        },
        resetFormStatus:false,
        carOrderStatusMap:"",
        followStatusMap:"",        
  	}
  },

  methods: {
    //列表查询
    seachData(){
      if(!this.resetFormStatus){
        var params=this.searchForm||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        params.endDate = setEndDateTime(params.endDate);
        agentHttp.postJson('adminApi/admin/vin_change/list?page='+params.page+'&rows='+params.rows,params ).then((data)=>{
          if (data.success) {
            this.tableData = data.data.tableData;
            this.carOrderStatusMap = data.data.carOrderStatusMap;
            this.followStatusMap = data.data.followStatusMap;             
          }
        })
      }
    },
    //延迟搜索
    debounceSeach(){
      this.tableData.page=1;
      debounce(this.seachData(),1000)
    },
    //重置
    resetSearchForm(formName) {
      this.resetFormStatus=true;
      this.tableData.page=1;
      this.tableData.rows=10;
      this.$refs[formName].resetFields();
      this.$nextTick(_ =>{
        this.resetFormStatus=false;
        this.seachData();
      })
    },
    handleSee(index, row){
      this.dialogSendData.isAdd=false;
      this.dialogSendData.id=row.id;
      this.dialogSendData.dialogFormVisible=true;
    },
    handleEdit(index, row){
      this.dialogSendData.isAdd=true;
      this.dialogSendData.id=row.id;
      this.dialogSendData.dialogFormVisible=true;
    }
  }
}
